<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Untitled Document</title>
		
		<script type="text/javascript">
			window.onload = function(){
				
				//点击每个 li 节点, 若 li 节点的文本值没有 ^^ 开头, 加上
				//有, 则去除
				
				var liNodes = document.getElementsByTagName("li");
				for(var i = 0; i < liNodes.length; i++){
					liNodes[i].onclick = function(){
						var val = this.firstChild.nodeValue;
						
						var reg = /^\^{3}/g;
						if(reg.test(val)){
							val = val.replace(reg, "");
						}else{
							val = "^^^" + val;
						}
						
						this.firstChild.nodeValue = val;
					}
				}
				
				/*
				
				//1. 使用正则表达式判断是否已 ^^ 开始
				//2. 调用字符串的 replace(reg, str) 方法除去指定的字符串. 
				
				var str = "^^abc";
				var reg = /^\^{2}/g;
				alert(reg.test(str)); //true
				str = str.replace(reg, "");
				alert(str);
				
				var str2 = "abc";
				alert(reg.test(str2)); //false
				*/
				
				
			}
		</script>
		
	</head>
	<body>
		<p>你喜欢哪个城市?</p>
		<ul id="city">
			<li id="bj" name="BeiJing">北京</li>
			<li>上海</li>
			<li>东京</li>
			<li>首尔</li>
		</ul>
		
		<br><br>
		<p>你喜欢哪款单机游戏?</p>
		<ul id="game">
			<li id="rl">红警</li>
			<li>实况</li>
			<li>极品飞车</li>
			<li>魔兽</li>
		</ul>
		
		<br><br>
		name: <input type="text" name="username" 
			id="name" value="atguigu"/>
	</body>
</html>	